package 算法题汇总;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class test11 {

    public static void main(String[] args) throws IOException {
        BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        String[] split = sc.readLine().split("],");
        int[][] grid1 = new int[split.length][split[0].length()-2];


        for (int i = 0; i < grid1.length; i++) {
            for (int j = 0; j < grid1[0].length; j++) {
                if(grid1[i][j] == 2) {
                    grid1[i][j] = 99999;
                } else if(grid1[i][j] == 0) {
                    grid1[i][j] = 2;
                }
            }
        }
        int i = minPathSum(grid1);
        System.out.println(9/2);
        System.out.println(i>99999 ?-1:i);
    }
    public static int minPathSum(int[][] grid){
        //当grid为空时，返回0
        if (grid==null || grid.length == 0||grid[0].length == 0){
            return 0;
        }
        //获取grid的行数和列数
        int rows = grid.length;
        int cols = grid[0].length;
        //额外数组data,大小和grid一样
        int[][] data = new int[rows][cols];
        //处理data第一列
        for (int i = 1; i < rows; ++i)
        {
            data[i][0] = data[i - 1][0] + grid[i][0];
        }
        //处理data第一行
        for (int i = 1; i < cols; ++i)
        {
            data[0][i] = data[0][i - 1] + grid[0][i];
        }
        //处理data非第一行和第一列的元素
        for (int i = 1; i < rows; ++i)
        {
            for (int j = 1; j < cols; ++j)
            {
                data[i][j] = Math.min(data[i][j - 1], data[i - 1][j]) + grid[i][j];
            }
        }
        //返回最短路径值
        return data[rows - 1][cols - 1];
    }
}
